package club.janna.concurrency.example.threadPool;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

@Slf4j
public class ThreadPoolExample5 {
    public static void main(String[] args) {
        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(3);
        CountDownLatch countDownLatch = new CountDownLatch(5);
        executorService.scheduleAtFixedRate(() -> {
            log.info("task is running1");
            countDownLatch.countDown();
            log.info("count: {}", countDownLatch.getCount());
        }, 1, 2, TimeUnit.SECONDS);
        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        executorService.shutdown();
    }
}
